package com.xiangyang.pos.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;

import com.journeyapps.barcodescanner.CaptureManager;
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
import com.xiangyang.pos.R;

/**
 * Created by Administrator on 2017/8/22 0022.
 *
 * 扫码
 *
 * @author YeDalin
 *
 */

public class PayScanActivity extends Activity {



    private DecoratedBarcodeView dbvPayScan;
    private CaptureManager capture;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_scan);

        initView();

        capture=new CaptureManager(this,dbvPayScan);
        capture.initializeFromIntent(getIntent(),savedInstanceState);
        capture.decode();

    }


    private void initView(){
        dbvPayScan=findViewById(R.id.dbv_pay_scan);
    }



    @Override
    protected void onResume() {
        super.onResume();
        capture.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        capture.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        capture.onDestroy();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        capture.onSaveInstanceState(outState);
    }



    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        capture.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return dbvPayScan.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
    }

}
